Rental Car

  • Design

    1. Functional Requirements

    1 Allow users to search for available cars by location, date, and time, and view car details such as make, model, year, and features.

    2 Users can book a car, select pick-up and drop-off locations, and make payments using a secure payment gateway.

    3 The system should send a confirmation email or SMS to the user with the booking details and rental agreement.

    4 Allow users to cancel or modify their bookings, and refund the appropriate amount based on the cancellation policy.

    5 The system should notify the user and the rental agency about any changes to the booking, such as delays, cancellations, or extensions.

    6 Provide an admin dashboard for the rental agency to add and manage cars, update rental rates, and view sales reports.

    7 The system should ensure data privacy and security, and protect against fraud and unauthorized access.

    2. Non-Functional Requirements

    1 The system should be highly available and scalable to handle peak loads during weekends and holidays.

    2 The system should be user-friendly, responsive, and accessible on different devices and platforms.

    3 The system should have a fast and reliable search and booking engine, and provide real-time updates on car availability and pricing.

    4 The system should have a robust and reliable payment gateway, and ensure secure and seamless transactions.

    5 The system should comply with industry standards and regulations, and protect the user's personal and financial data.

    3. Low level code

    
    
                          //Person class as a base class for User and Admin classes
    class Person {
      constructor(firstName, lastName, email, phoneNo, address) {
        this.firstName = firstName;
        this.lastName = lastName;
        this.email = email;
        this.phoneNo = phoneNo;
        this.address = address;
      }
    }
    
    //User class, which extends the Person class
    class User extends Person {
      constructor(firstName, lastName, email, phoneNo, address, password) {
        // Call the parent class constructor with super()
        super(firstName, lastName, email, phoneNo, address);
        // Initialize the password and rentals array properties
        this.password = password;
        this.rentals = [];
      }
    
      //Method to search for available vehicles based on location and rental dates
      searchVehicles(location, startDate, endDate) {
        // search vehicles logic here
      }
    
      //Method to rent a vehicle and add a new rental to the rentals array
      rentVehicle(vehicle, startDate, endDate) {
        // rent vehicle logic here
        const rental = new Rental(this, vehicle, startDate, endDate, totalCost);
        this.rentals.push(rental);
        return rental;
      }
    
      //Method to view the user's rental history
      viewRentals() {
        // view rentals logic here
      }
    
      //Method to modify an existing rental by rental ID
      modifyRental(rentalId, newStartDate, newEndDate) {
        // modify rental logic here
         const rental = this.rentals.find((r) => r.id === rentalId);
        if (rental) {
          rental.modifyRental(newStartDate, newEndDate);
        }
      }
    
      //Method to cancel an existing rental by rental ID
      cancelRental(rentalId) {
        // cancel rental logic here
        const rentalIndex = this.rentals.findIndex((r) => r.id === rentalId);
        if (rentalIndex !== -1) {
          this.rentals.splice(rentalIndex, 1);
        }
      }
    
      //Method to make a payment for a rental or other expense
      makePayment(paymentInfo) {
        // make payment logic here
      }
      
      //Method to submit the return date of a rental by rental ID
      submitVehicleReturnDate(rentalId, returnDate) {
        const rental = this.rentals.find((r) => r.id === rentalId);
        if (rental) {
          rental.submitVehicleReturnDate(returnDate);
        }
      }
    }
    
    //Admin class, which also extends the Person class
    class Admin extends Person {
      constructor(firstName, lastName, email, phoneNo, address, password) {
        // Call the parent class constructor with super()
        super(firstName, lastName, email, phoneNo, address);
        // Initialize the password property
        this.password = password;
      }
    
      //Method to manage vehicles (e.g. add, delete, update)
      manageVehicles() {
        // manage vehicles logic here
      }
    
      //Method to manage rentals (e.g. approve, deny, modify)
      manageRentals() {
        // manage rentals logic here
      }
    
      //Method to view all rentals (for all users)
      viewRentals() {
        // view rentals logic here
      }
    
      //Method to cancel an existing rental by rental ID
      cancelRental(rentalId) {
        // cancel rental logic here
      }
    }
    
    
    
    
    
    class Vehicle {
      constructor(make, model, year, type, capacity, pricePerDay, location, color, brand) {
        this.make = make;
        this.model = model;
        this.year = year;
        this.type = type;
        this.capacity = capacity;
        this.pricePerDay = pricePerDay;
        this.location = location;
        this.color = colorl
        this.brand = brand;
      }
    }
    
    class Rental {
      constructor(user, vehicle, startDate, endDate, totalCost) {
        this.user = user;
        this.vehicle = vehicle;
        this.startDate = startDate;
        this.endDate = endDate;
        this.totalCost = totalCost;
        this.status = "Booked";
      }
    
      modifyRental(newStartDate, newEndDate) {
        // modify rental logic here
      }
    
      cancelRental() {
        // cancel rental logic here
      }
      
       submitVehicleReturnDate(returnDate) {
        this.returnDate = returnDate;
        if (this.returnDate > this.endDate) {
          // raise alert if the car is returned late
          console.log("Late return alert!");
        }
      }
    }
    
    class Payment {
      constructor(cardholderName, cardNumber, expiryDate, cvv) {
        this.cardholderName = cardholderName;
        this.cardNumber = cardNumber;
        this.expiryDate = expiryDate;
        this.cvv = cvv;
      }
    
      makePayment(amount) {
        // make payment logic here
      }
    }
    
    

    4. Database